<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>App用户行为数据分析</title>
    <link rel="stylesheet" href="/static/css/index.css">
    <script type="text/javascript" src="/static/js/vue.min.js"></script>
    <script type="text/javascript" src="/static/js/index.js"></script>
    <script type="text/javascript" src="/static/js/echarts.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.min.js"></script>
</head>
<body>


<div id="daapp">
    <el-row>
        <el-col :span="12" style="text-align:center;">
            <div class="grid-content bg-purple" style="margin-top: 30px;">
                <h3 style="text-align:center;">更新数据接入信息</h3>
                <el-form :model="Form" :rules="rules" ref="Form" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="百度服务" prop="baidufuwu">
                        <el-input type="textarea" rows=4 v-model="Form.baidufuwu" style="width: 80%;"></el-input>
                    </el-form-item>
                    <el-form-item label="用户应用" prop="yonghuyingyong">
                        <el-input type="textarea" rows=10 v-model="Form.yonghuyingyong" style="width: 80%;"></el-input>
                    </el-form-item>
                    <el-form-item label="数据接入" prop="shujujieru">
                        <el-input type="textarea" rows=10 v-model.trim="Form.shujujieru" style="width: 80%;"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('Form')">立即创建</el-button>
                        <el-button @click="resetForm('Form')">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-col>
        <el-col :span="12" style="text-align:center;">
            <div class="grid-content bg-purple">
                <h3 style="text-align:center;">数据接入任务管理</h3>
                <el-table
                        :data="tableData"
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="任务ID">
                    </el-table-column>
                    <el-table-column
                            prop="next_run_time"
                            label="下一次运行时间">
                    </el-table-column>
                    <el-table-column
                            label="操作">
                        <template slot-scope="scope">
                            <el-button
                                    size="mini"
                                    type="danger"
                                    v-if="scope.row.enable==='1'"
                                    @click="handleZanTing(scope.$index, scope.row)">暂停
                            </el-button>
                            <el-button
                                    size="mini"
                                    type="warning"
                                    v-if="scope.row.enable==='0'"
                                    @click="handleHuiFu(scope.$index, scope.row)">恢复
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </el-col>
    </el-row>
</div>
<script>
    new Vue({
        data() {
            return {
                tableData: [],
                Form: {
                    baidufuwu: '',
                    yonghuyingyong: '',
                    shujujieru: '',
                },
                rules: {
                    baidufuwu: [
                        {required: true, message: '请填写百度服务', trigger: 'blur'}
                    ],
                    yonghuyingyong: [
                        {required: true, message: '请填写用户应用', trigger: 'blur'}
                    ],
                    shujujieru: [
                        {required: true, message: '请填写数据接入', trigger: 'blur'}
                    ],
                }
            }
        },
        mounted() {
            this.huoqushuju();
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        //alert('submit!');
                        var that = this;
                        $.ajax({
                            type: 'post',
                            url: "http://127.0.0.1:8000/qbrenwuguanli/",//这里是url
                            data: {
                                qingqiuming: "gengxinshujujieru",
                                yonghuyingyong: that.Form.yonghuyingyong,
                                shujujieru: that.Form.shujujieru,
                                baidufuwu: that.Form.baidufuwu,
                                csrfmiddlewaretoken: '{{ csrf_token }}'
                            },
                            dataType: "json",
                            success: function (datat) {
                                //console.log(datat)
                                if (datat.res === "提交成功") {
                                    that.huoqushuju();
                                    that.$message.success('提交成功');
                                }
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            handleZanTing(index, row) {
                //console.log(row.id);
                var that = this;
                $.ajax({
                    type: 'post',
                    url: "http://127.0.0.1:8000/qbrenwuguanli/",//这里是url
                    data: {qingqiuming: "mouzanting", renwuid: row.id, csrfmiddlewaretoken: '{{ csrf_token }}'},
                    dataType: "json",
                    success: function (datat) {
                        //console.log(datat)
                        if (datat.res === "暂停成功") {
                            that.huoqushuju();
                            that.$message.success('暂停成功');
                        }
                    }
                })
            },
            handleHuiFu(index, row) {
                //console.log(row.id);
                var that = this;
                $.ajax({
                    type: 'post',
                    url: "http://127.0.0.1:8000/qbrenwuguanli/",//这里是url
                    data: {qingqiuming: "mouhuifu", renwuid: row.id, csrfmiddlewaretoken: '{{ csrf_token }}'},
                    dataType: "json",
                    success: function (datat) {
                        //console.log(datat)
                        if (datat.res === "恢复成功") {
                            that.huoqushuju();
                            that.$message.success('恢复成功');
                        }
                    }
                })
            }, huoqushuju() {
                var that = this;
                $.ajax({
                    type: 'get',
                    url: "http://127.0.0.1:8000/getDataByKey/?type=huoqurenwuid",//这里是url
                    dataType: 'json',
                    async: false,
                    success: function (datat, heads, status) {
                        that.tableData = datat.data;
                    }
                });
            },
        }
    }).$mount('#daapp')
</script>

</body>
</html>